package com.yuanfeng.order.controller;

import com.fasterxml.jackson.core.JsonParseException;
import com.fasterxml.jackson.databind.JsonMappingException;
import com.yuanfeng.commoms.util.ResponseResult;
import io.seata.core.exception.TransactionException;
import io.seata.spring.annotation.GlobalTransactional;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import java.io.IOException;

/**
 * @ClassName OrderCreateController
 * @Description 创建订单 计算价格
 * @Author cyp
 * @Date 2023-05-26 13:28:35
 * @Version 1.0
 **/
@RestController
@CrossOrigin
@RequestMapping("order")
public class OrderCreateController extends BaseController {



    /**
     * 计算价格
     *
     * @param message
     * @return
     */
    @RequestMapping("/calculatePrice")
    public ResponseResult calculatePrice(@RequestBody String message) {
        ResponseResult result = orderCreateService.calculatePrice(message);
        return result;
    }


    /**
     * App下单
     *
     * @param para
     * @return
     * @throws IOException
     * @throws JsonMappingException
     * @throws JsonParseException
     */
    @GlobalTransactional
    @RequestMapping("/appCreateOrders")
    public ResponseResult AppCreateOrders(@RequestBody String para, HttpServletRequest request)
            throws JsonParseException, JsonMappingException, IOException, TransactionException {
        ResponseResult result = orderCreateService.createOrders(para, request);
        return result;

    }

}
